//
//  UICollectionView+Manage.m
//  MGPublic
//
//  Created by lhongl on 2025/10/23.
//

#import "UICollectionView+Manage.h"

@implementation UICollectionView (Manage)

#pragma mark - 注册cell
- (void)registerCellWithNibName:(NSString *)nibName {
    [self registerNib:[UINib nibWithNibName:nibName bundle:nil] forCellWithReuseIdentifier:nibName];
}

- (void)registerCellWithClass:(Class)cellClass {
     NSString *identifier = NSStringFromClass(cellClass);
    [self registerClass:cellClass forCellWithReuseIdentifier:identifier];
}

#pragma mark - 注册footerView
- (void)registerFooterViewWithNibName:(NSString *)nibName {
    [self registerNib:[UINib nibWithNibName:nibName bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:nibName];
}

- (void)registerFooterViewWithClass:(Class)aClass {
    NSString *identifier = NSStringFromClass(aClass);
    [self registerClass:aClass forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:identifier];
}

#pragma mark - 注册Headerview
- (void)registerHeaderViewWithNibName:(NSString *)nibName {
    [self registerNib:[UINib nibWithNibName:nibName bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:nibName ];
}
- (void)registerHeaderViewWithClass:(Class)aClass {
    NSString *identifier = NSStringFromClass(aClass);
    [self registerClass:aClass forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:identifier];
}

#pragma mark - cell
- (__kindof UICollectionViewCell *)dequeueReusableCellWithClass:(Class)cellClass forIndexPath:(NSIndexPath *)indexPath {
    NSString *identifier = NSStringFromClass(cellClass);
    return [self dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
}

#pragma mark - headerView
- (__kindof UICollectionReusableView *)dequeueReusableHeaderWithClass:(Class)aClass forIndexPath:(NSIndexPath *)indexPath {
    NSString *identifier = NSStringFromClass(aClass);
    return [self dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:identifier forIndexPath:indexPath];
}

- (__kindof UICollectionReusableView *)dequeueReusableHeaderWithReuseIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath {
    return [self dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:identifier forIndexPath:indexPath];
}

#pragma mark - footerView
- (__kindof UICollectionReusableView *)dequeueReusableFooterWithClass:(Class)aClass forIndexPath:(NSIndexPath *)indexPath {
    NSString *identifier = NSStringFromClass(aClass);
    return [self dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:identifier forIndexPath:indexPath];
}

- (__kindof UICollectionReusableView *)dequeueReusableFooterWithReuseIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath {
    return [self dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:identifier forIndexPath:indexPath];
}

@end
